#!/usr/bin/python

import optparse

from GitSvnServer.server import SvnServer


version = "pre-alpha"

description = \
    """This program attempts to server one or more git repositories using the
    Subversion svn:// protocol.
    """

epilog = \
    """WARNING: Currently there is a lot that doesn't work at all, doesn't work
    properly, or doesn't handle errors.  Anyone who configures this program to
    serve a git repository that isn't disposable is possibly insane, and certainly
    on the own.
    """


def main():
    parser = optparse.OptionParser(description=description,
                                   epilog=epilog,
                                   version=version)

    parser.add_option('-c', '--config', metavar='CONFIG', default='/etc/git-svnserver/config',
                      help='Load configuration from CONFIG')

    parser.add_option('-i', '--ip', metavar='ADDRESS', default=None,
                      help='Bind to the specifed IP address (can be v6 if '
                           'supported by Python).  The default is all addresses.')

    parser.add_option('-p', '--port', metavar='PORT', default=3690, type='int',
                      help='Bind to the specified port number, instead of '
                           'the default SVN port.')

    parser.add_option('-f', '--foreground', default=False, action="store_true",
                      help='Run in the foreground instead of as a daemon.')

    parser.add_option('-d', '--debug', default=False, action="store_true",
                      help='Run in debug mode (implies --foreground).')

    parser.add_option('-l', '--log', default='svnserver.log',
                      help='File to log to if running as daemon.')

    parser.add_option('', '--pidfile', default=None, metavar='PIDFILE',
                      help='Store the pid of the server process in PIDFILE.')

    parser.add_option('-m', '--show-messages', default=False,
                      action='store_true',
                      help='Include the contents of messages sent and received '
                           'in the debug/log output.')

    parser.add_option('', '--max-message-debug-len', default=0, type='int',
                      metavar='LENGTH',
                      help='The maximum length of a message that should be '
                           'written to the log (longer messages will be truncated)')

    options, args = parser.parse_args()

    server = SvnServer(options)
    server.start()


if __name__ == "__main__":
    main()
